package com.hk.modules.folder.controller;


import com.hk.common.utils.ResponseUtils;
import com.hk.modules.folder.pojo.CopyFileVo;
import com.hk.modules.folder.pojo.FolderPojo;
import com.hk.modules.folder.service.FolderService;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Date;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zy
 * @since 2024-04-28
 */
@RestController
@RequestMapping("/folder")
public class FolderController {

    @Autowired
    private FolderService folderService;

    @PostMapping("/save")
    public ResponseEntity<Object> addObj(@RequestBody FolderPojo p) {
        p.setCreateTime(new Date()).setUpdateTime(new Date());
        return ResponseUtils.tryReturn("新增信息异常", () -> folderService.saveOrUpdate(p));
    }

    @PostMapping("/update")
    public ResponseEntity<Object> updateObj(@RequestBody FolderPojo p) {
        p.setUpdateTime(new Date());
        return ResponseUtils.tryReturn("修改信息异常", () ->
                folderService.updateById(p));
    }

    @PostMapping("/delete")
    public ResponseEntity<Object> deleteObj(@RequestBody FolderPojo p) {
        return ResponseUtils.tryReturn("删除信息异常", () -> {
            folderService.removeById(p.getId());
            return "成功";
        });
    }

    @GetMapping("/getFileArr")
    public ResponseEntity<Object> getFileArr(FolderPojo p) {
        return ResponseUtils.tryReturn("获取信息异常", () -> folderService.getFileArr(p));
    }

    @PostMapping("/copyFile")
    public ResponseEntity<Object> copyFile(@RequestBody CopyFileVo p) {
        return ResponseUtils.tryReturn("获取信息异常", () -> folderService.copyFile(p));
    }
}

